﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (sendEmail() == true)
        {
            thankyou();
            lblmsg.Text = "Enquiry Sent!";

        }
        else
        {
            lblmsg.Text = "Enquiry was not Sent!";
        }

    }
    public bool sendEmail()
    {
        try
        {
           
            MailMessage mail = new MailMessage();

            mail.From = new System.Net.Mail.MailAddress("shahtanvi0612@gmail.com", firstName.Value);

            mail.Subject = " Orion Enquiry";

            mail.To.Add("shahtanvi0612@gmail.com");

            mail.Body = "From :" + firstName.Value + Environment.NewLine + "Email :" + useremail.Value + "Enquiry :" + messageBody.Value;

            SmtpClient smtp = new SmtpClient();
            smtp.UseDefaultCredentials = false;
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential("shahtanvi0612@gmail.com", "makesure");
            smtp.EnableSsl = true;
            smtp.Send(mail);
            return true;

        }

        catch (Exception ex)
        {
            return false;
        }
    }

    public void thankyou()
    {


        MailMessage mail = new MailMessage();

        mail.From = new System.Net.Mail.MailAddress("shahtanvi0612@gmail.com", firstName.Value);

        mail.Subject = "Thank You";

        mail.To.Add(useremail.Value);

        mail.Body = "Thank you for contacting us" + Environment.NewLine + "We will get back to you soon";

        SmtpClient smtp = new SmtpClient();
        smtp.UseDefaultCredentials = false;
        smtp.Port = 587;
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential("shahtanvi0612@gmail.com", "makesure");
        smtp.EnableSsl = true;
        smtp.Send(mail);


    }
}
